/*
 * @Author: fanweihua
 * @Date: 2020-12-10 11:51:58
 * @LastEditTime: 2021-07-21 10:12:35
 * @Description: React、ReactDOM、RootRouter、Redux
 */
'use strict';
import React from 'react';
import ReactDOM from 'react-dom';
import RootRouter from './router/index'; // 路由入口
import { Provider, useSelector } from 'react-redux';
import { IntlProvider } from 'react-intl';
import { ConfigProvider } from 'antd';
import { title } from './config/systemConfig'; // 系统内部配置文件
import registerStore from '@/common/store/registerStore';
import './index.less'; // 主框架样式
import './static/theme/theme.less'; // 主题
if (module.hot && process.env.NODE_ENV === 'development') {
  module.hot.accept();
}
if (title) {
  document.title = title;
}

/**
 * 创建store
 */
const context = require.context('./model', true, /\.js$/);
const storeRegister = registerStore();
const store = storeRegister.useModel(context.keys().map(key => context(key).default)).run();
/**
 * antd的多语言集合
 */
const AntdLocales = {
  zh: require('antd/es/locale/zh_CN').default,
  en: require('antd/es/locale/en_US').default
};
/**
 * 多语言集合
 */
const Locals = {
  zh: require('./static/locale/zh').default,
  en: require('./static/locale/en').default
};
/**
 * 入口容器
 */
const RootContainer = () => {
  const { locale } = useSelector(state => state.global);
  return (
    <IntlProvider messages={Locals[locale]} locale="zh">
      <ConfigProvider locale={AntdLocales[locale]}>
        {/* 路由入口 */}
        <RootRouter />
      </ConfigProvider>
    </IntlProvider>
  );
};
/**
 * 入口包裹容器
 */
const Container = (
  <Provider store={store}>
    {/* 入口容器 */}
    <RootContainer />
  </Provider>
);
ReactDOM.render(Container, document.getElementById('root'));
